package CeShi;
import java.io.*;
/**
 * 将指定目录下所有文件中的内容，写入另一个文本文件中
 */
public class Test01 {
    public static void main(String[] args) {
        File file = new File("E:\\测试1");
        File file1 = new File("E:\\测试1\\Test.txt");
        BufferedReader br=null;
        BufferedWriter bw=null;
        try {
            bw=new BufferedWriter(new FileWriter(file1));
        } catch (IOException e) {
            e.printStackTrace();
        }
        File[] files=file.listFiles();
        for (File fi:files){
            try {
                br=new BufferedReader(new FileReader(fi));
                while(true){
                    String line= br.readLine();
                    if (line==null){
                        break;
                    }
                    bw.write(line);
                    bw.flush();
                    bw.newLine();
                }

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (null!=bw){
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (null!=br){
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
